<?php

namespace app\admin\controller\users;

use app\common\controller\Backend;
use think\Db;
use think\Env;
//use think\exception\ValidateException;

/**
 * 合伙人-日志
 *
 * @icon fa fa-table
 * @remark 当一个页面上存在多个Bootstrap-table时该如何控制按钮和表格
 */
class Bigss extends Backend
{
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];
    protected $relationSearch = true;

    /**
     * @var \app\admin\model\User
     */
    protected $model = null;
    protected $categorylist = [];
    private $redis;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Apply;
        $this->redis = redis(Env::get('redis.host'), Env::get('redis.port'), Env::get('redis.pwd'), Env::get('redis.db'));
    }

    /**
     * 查看
     */
    public function index()
    {

        if (isset(request()->param()['big_id'])){
            $id = request()->param()['big_id'];
        }else{
            $id = 0;
        }

        //$this->view->assign("id", $id);
        $this->assignconfig('id',$id);
        return $this->view->fetch();
    }

    public function table1()
    {
        $this->model = model('Bigsss');
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            if (isset(request()->param()['big_id'])){
                $id = request()->param()['big_id'];
            }else{
                $id = 0;
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->with([
                    'info' => function ($query) {
                        $query->withField('id,number');
                    },
                    'order' => function ($query) {
                        $query->withField('id,code,create_time');
                    }
                ])
                ->where($where)
                ->where(['bigsss.type'=>1,'bigsss.big_id'=>$id])
                ->order('bigsss.id', 'desc')
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch('index');
    }

    public function table2()
    {
        $this->model = model('Bigsss');
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            if (isset(request()->param()['big_id'])){
                $id = request()->param()['big_id'];
            }else{
                $id = 0;
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->with([
                    'info' => function ($query) {
                        $query->withField('id,number');
                    },
                    'order' => function ($query) {
                        $query->withField('id,code,create_time');
                    },
                    'bigs' => function ($query) {
                        $query->withField('id,code');
                    },
                ])
                ->where($where)
                ->where(['bigsss.type'=>2,'bigsss.big_id'=>$id])
                ->order('bigsss.id', 'desc')
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch('index');
    }

    public function table3()
    {
        $this->model = model('Bigss');
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            if (isset(request()->param()['big_id'])){
                $id = request()->param()['big_id'];
            }else{
                $id = 0;
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
//                ->with([
//                    'big' => function ($query) {
//                        $query->withField('id,code');
//                    },
//                ])
                ->where($where)
                ->where(['bigss.type'=>1,'bigss.big_id'=>$id])
                ->order('bigss.id', 'desc')
                ->paginate($limit);

            if (!empty($list->items())){
                foreach ($list->items() as $k=>$v){
                    switch ($v->status){
                        case 0:
                            $list->items()[$k]['status'] = '审核中';
                            break;
                        case 1:
                            $list->items()[$k]['status'] = '成功';
                            break;
                        case 2:
                            $list->items()[$k]['status'] = '失败';
                            break;
                        default:
                            $$list->items()[$k]['status'] = '';
                            break;
                    }

                }
            }

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch('index');
    }

    public function table4()
    {
        $this->model = model('Bigss');
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            if (isset(request()->param()['big_id'])){
                $id = request()->param()['big_id'];
            }else{
                $id = 0;
            }

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
//                ->with([
//                    'big' => function ($query) {
//                        $query->withField('id,code');
//                    },
//                ])
                ->where($where)
                ->where(['bigss.type'=>2,'bigss.big_id'=>$id])
                ->order('bigss.id', 'desc')
                ->paginate($limit);

            if (!empty($list->items())){
                foreach ($list->items() as $k=>$v){
                    switch ($v->status){
                        case 0:
                            $list->items()[$k]['status'] = '审核中';
                            break;
                        case 1:
                            $list->items()[$k]['status'] = '成功';
                            break;
                        case 2:
                            $list->items()[$k]['status'] = '失败';
                            break;
                        default:
                            $$list->items()[$k]['status'] = '';
                            break;
                    }

                }
            }

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch('index');
    }


}
